package edu.tju.belongings;


import java.sql.SQLException;
import java.util.Date;


import org.infohazard.maverick.flow.ControllerContext;

import com.younker.waf.maverick.DispatchCtl;

import edu.tju.car.Car;
import edu.tju.car.ICarDao;
import edu.tju.car.IbatisCarDao;
import edu.tju.model.IStudentDao;
import edu.tju.model.IbatisStudentDao;
import edu.tju.model.Student;




public class BelongingsSetAction extends DispatchCtl{
	
	private final static String SUCCESS_INSERT = "success_insert";
	private final static String SUCCESS_INSERT_CAR = "success_insert_car";
	
	private final static String SUCCESS_DELETE = "success_delete";
	@Override
	protected Object makeFormBean(ControllerContext arg0) {
		
		return new BelongingsSetAction();
	}
	private long id;

    private String name;
    
	private String remark;
	
	private String fee;
	
	private String principal;
	
	private Date buyingTime;
	
	private int price;
	
	private String  license;
	


	public String getPrincipal() {
		return principal;
	}
	public void setPrincipal(String principal) {
		this.principal = principal;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getFee() {
		return fee;
	}
	public void setFee(String fee) {
		this.fee = fee;
	}

	
	public Date getBuyingTime() {
		return buyingTime;
	}
	public void setBuyingTime(Date buyingTime) {
		this.buyingTime = buyingTime;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getLicense() {
		return license;
	}
	public void setLicense(String license) {
		this.license = license;
	}
	IBelongingsDao belongingsDao=new IbatisBelongingsDao();
	public  String insertBelongings(Object formBean, ControllerContext ctx)throws SQLException {
		
		BelongingsSetAction bean = (BelongingsSetAction) formBean;
		Date date=new Date();
		String academic=Integer.toString(date.getYear()+1900);
		
		//System.out.print("&&&&");
		
		
		Belongings belongings=new Belongings();
		belongings.setName(bean.getName());
		belongings.setFee(bean.getFee());
		belongings.setRemark(bean.getRemark());
		belongings.setSetTime(date);
		belongings.setPrincipal(bean.getPrincipal());
		belongings.setAcademic(academic);
		
		belongingsDao.insertBelongings(belongings);
		
		

		
		ctx.setModel(belongings);
		//System.out.print("&&&&");
			return SUCCESS_INSERT;
		}
	public String deleteBelongings(Object formBean, ControllerContext ctx)throws SQLException {
		
		BelongingsSetAction bean = (BelongingsSetAction) formBean;
		
		belongingsDao.deleteBelongings(bean.getId());
		
		return SUCCESS_DELETE;
		
		
	}
	ICarDao carDao=new IbatisCarDao();
	public String insertCar(Object formBean, ControllerContext ctx)throws SQLException {
		
		BelongingsSetAction bean = (BelongingsSetAction) formBean;
		 Car car=new Car();
		 car.setName(bean.getName());
		 car.setBuyingTime(bean.getBuyingTime());
		 car.setLicense(bean.getLicense());
		 car.setState(Car.N);
		 car.setPrice(bean.getPrice());
		 carDao.insertCar(car);
		 ctx.getRequest().setAttribute(RET_CODE, RC_SUCCESS);
		 
		return SUCCESS_INSERT_CAR;
		
		
	}
    
   
	
}
	
